package com.ruoyi.project.sms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.sms.domain.SmsTopic;
import com.ruoyi.db.sms.domain.query.SmsTopicQueryVo;
import com.ruoyi.project.sms.service.SmsTopicService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 推荐专题Controller
 *
 * @author yfy
 * @date 2020-04-20
 */
@Api(tags="sms管理：推荐专题管理")
@RestController
@RequestMapping("/sms/topic")
public class SmsTopicController extends BaseController
{
    @Autowired
    private SmsTopicService smsTopicService;

    @ApiOperation("查询推荐专题列表")
    @PreAuthorize("@ss.hasPermi('sms:topic:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsTopicQueryVo smsTopicQueryVo)
    {
        startPage();
        List<SmsTopic> list = smsTopicService.selectSmsTopicList(smsTopicQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出推荐专题列表")
    @Log(title = "推荐专题", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('sms:topic:export')")
    @GetMapping("/export")
    public AjaxResult export(SmsTopicQueryVo smsTopicQueryVo)
    {
        List<SmsTopic> list = smsTopicService.selectSmsTopicList(smsTopicQueryVo);
        ExcelUtil<SmsTopic> util = new ExcelUtil<SmsTopic>(SmsTopic.class);
        return util.exportExcel(list, "topic");
    }

    @ApiOperation("获取推荐专题详细信息")
    @Log(title = "推荐专题", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('sms:topic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsTopicService.selectSmsTopicById(id));
    }

    @ApiOperation("新增推荐专题")
    @Log(title = "推荐专题", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms:topic:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SmsTopic smsTopic)
    {
        return toAjax(smsTopicService.insertSmsTopic(smsTopic));
    }

    @ApiOperation("修改推荐专题")
    @Log(title = "推荐专题", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms:topic:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SmsTopic smsTopic)
    {
        return toAjax(smsTopicService.updateSmsTopic(smsTopic));
    }

    @ApiOperation("删除推荐专题")
    @Log(title = "推荐专题", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms:topic:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsTopicService.deleteSmsTopicByIds(ids));
    }
}
